package ru.brostudios.cosmicdonutlivewallpapers;

import javax.microedition.khronos.opengles.GL10;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLUtils;

public class Texture {
	
	public int glid, width, height;
	
	public Texture(AssetManager assets, String fileName, GL10 gl) {
		int[] textures = new int[1];
		gl.glEnable(GL10.GL_TEXTURE_2D);
		gl.glGenTextures(1, textures, 0);
		gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
		gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
		try {
			Bitmap bitmap = BitmapFactory.decodeStream(assets.open(fileName));
			glid = textures[0];
			width = bitmap.getWidth();
			height = bitmap.getHeight();
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
			bitmap.recycle();
		} catch(Exception e) {}
		gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
		gl.glDisable(GL10.GL_TEXTURE_2D);
	}

}